import React, { PureComponent } from 'react';
import { Form, Descriptions, Card, Divider, message, Table, Typography } from 'antd';
import moment from 'moment';
import { connect } from 'dva';
import router from 'umi/router';
import Ellipsis from '@/components/Ellipsis';
import styles from '../../Repair.less';
const FormItem = Form.Item;
const renderContent = (value, row, index) => {
    const obj = {
      children: value,
      props: {},
    };
    if (index === 13) {
      obj.props.colSpan = 0;
    }
    return obj;
  };
@Form.create()
@connect(({ assessment, loading }) => ({
    CheckedCompany: assessment.CheckedCompany,
    roadTemplateList: assessment.roadTemplateList,
    loading: loading.effects['assessment/fetchGetCheckedCompany'] || loading.effects['assessment/fetchGetTemplate']
}))

class AssessDesForPip extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
        };
        this.dispatch = this.props.dispatch;
        this.routeParams = this.props.match.params;

    }
    returnColumn = () => {
        return [


            {
                title: '序号',
                dataIndex: 'px',
                width: 50,

            },
            {
                title: '指标归类',
                dataIndex: 'flkhzb',
                width:100,
                render: (value, row, index) => {
                    const obj = {
                        children: value,
                        props: {},
                    };
                    if (index === 0) {
                        obj.props.rowSpan = 6;
                    }
                    if (index === 1||index === 2||index === 3||index === 4||index === 5) {
                        obj.props.rowSpan = 0;
                    }

                    if (index === 6) {
                        obj.props.rowSpan = 4;
                    }
                    if (index === 7||index === 8||index === 9) {
                        obj.props.rowSpan = 0;
                    }
                    if (index === 10) {
                        obj.props.rowSpan = 3;
                    }
                    if (index === 11||index === 12) {
                        obj.props.rowSpan = 0;
                    }
                   
                    return obj;
                },
            },

            {
                title: '考核指标',
                dataIndex: 'khzb',
                render:renderContent
            },
            {
                title: '指标详解',

                dataIndex: 'zbxj',
                render:renderContent

            },
            {
                title: '单次扣分',
                width:100,
                dataIndex: 'zbkf',
                render:renderContent
            },
            {
                title: '总分',
                width:50,
                dataIndex: 'zbzf',
                render:renderContent
            },
            // {
            //     title: '单次扣分数量',
            //     dataIndex: 'sl',
            // },
            {
                title: '总扣分',
                width:70,
                dataIndex: 'MinusedNum',
                render: (text, record) => <Typography.Text type="danger" strong={true}>{text}</Typography.Text>
            },
            {
                title: '总得分',
                width:70,
                dataIndex: 'hasMinusedNum',
                render: (text, record) =>  <Typography.Text strong={true}>{text ==0|| text ? text : record.zbzf}</Typography.Text>
            },
        ]

    }
    fetchGetCheckedCompany() {
        this.routeParams.quota = null;
        this.dispatch({
            type: 'assessment/fetchGetCheckedCompany',
            payload: this.routeParams,
            callback: response => {
                message.error.error('详情获取失败');
                console.log(response);
            },
        });
    }
    fetchGetTemplate = ({ type = null } = {}) => {
        this.dispatch({
            type: 'assessment/fetchGetTemplate',
            payload: {
                type: type,
                year: new Date().getFullYear()
            },
            callback: response => {
                message.error.error('考核模版获取失败');
                console.log(response);
            },
        });
    }
    componentDidMount() {
        if (!this.props.roadTemplateList) this.fetchGetTemplate({ type: 1 });
        this.fetchGetCheckedCompany();


    }
    render() {
        const { CheckedCompany, roadTemplateList, loading } = this.props;
        console.log(roadTemplateList)
        return (

            <>
                <Card
                    title={
                        <span style={{ borderLeft: '4px solid #3CB371', paddingLeft: '10px' }}>
                            道路/桥梁养护考核评价表 | {CheckedCompany ? CheckedCompany.data[0].khbmmc : null} | {CheckedCompany ? CheckedCompany.data[0].nf : null}年/{CheckedCompany ? CheckedCompany.data[0].yf : null}月份
                        </span>
                    }
                    style={{ margin: '10px' }}
                >
                    <Table
                        className={styles.RepairTable}
                        size="small"
                        align={'center'}
                        bordered
                        loading={loading}
                        dataSource={roadTemplateList ? roadTemplateList.data2 : null}
                        columns={this.returnColumn()}
                        pagination={false}
                    />
                </Card>
            </>);
    }
}

export default AssessDesForPip;